//
//  ViewController.m
//  10.UIView和核心动画区别
//
//  Created by J on 16/3/22.
//  Copyright © 2016年 J. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (weak, nonatomic) IBOutlet UIView *grayView;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [_grayView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)]];
    
    
}

- (void)tap{
    static  int i = 0;
    NSLog(@"%zd",i++);
}


- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    
//    CABasicAnimation* basic = [CABasicAnimation animation];//动画过程中 可以响应事件
//    basic.keyPath = @"position";
//    basic.toValue = [NSValue valueWithCGPoint:CGPointMake(150, 400)];
//    
//    //设置必须放在layer添加动画之前
//    basic.removedOnCompletion = NO;//动画结束之后是否移除动画
//    basic.fillMode = kCAFillModeForwards;//保存最新状态
//    
//    basic.delegate = self;
//    basic.duration = 5.0;
//    [_grayView.layer addAnimation:basic forKey:nil];


    
    
    //使用UIView动画 执行之后layer的属性值发生了改变 因为是通过修改属性的真实值达到动画的目的
    //不需要与用户交互都使用核心动画
//    NSLog(@"%@",NSStringFromCGPoint(_grayView.layer.position));
//    [UIView animateWithDuration:5 animations:^{//动画过程中 不可以响应事件
//        
//        _grayView.layer.position = CGPointMake(150, 400);
//    }completion:^(BOOL finished) {
//        
////        NSLog(@"%@",NSStringFromCGPoint(_grayView.layer.position));
//
//    }];
  
    

    
}

//核心动画一切都是假象,并不会真实的改变图层的属性值
- (void)animationDidStart:(CAAnimation *)anim{//动画开始和结束之后layer的值并没有发生改变
    
    NSLog(@"%@",NSStringFromCGPoint(_grayView.layer.position));

}


- (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag{
    
    NSLog(@"%@",NSStringFromCGPoint(_grayView.layer.position));

}


@end
